package com.example.utils;

import java.io.File;
import java.util.List;
import java.util.Map;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.example.entity.DbBlock;
import org.apache.poi.ss.formula.functions.T;

/**
 * Copyright: Copyright (c) 2022
 *
 * <p>
 * Description:
 *
 * @author LiuFeng
 * @version 2022/11/11 9:04
 * @since
 */
public class ExcelUtils {

    private ExcelUtils() {
    }

    public static List readExcel(File file) {
        return EasyExcelFactory.read(file, new AnalysisEventListener<Map<String, String>>() {

            @Override
            public void invoke(Map<String, String> data, AnalysisContext context) {
                System.out.println("数据量大小是：" + data.size());
            }

            @Override
            public void doAfterAllAnalysed(AnalysisContext context) {

            }
        }).sheet("变量").doReadSync();
    }

    public static List<T> readExcel(File file, Class clazz){

        List<T> objects = EasyExcelFactory.read(file).head(clazz).headRowNumber(2)
                .sheet("变量").doReadSync();

        return objects;
    }

    public static void main(String[] args) {
        File file = new File("F:\\IdeaProjects\\opc\\src\\main\\resources\\file\\二标段.xlsx");
//        List list = readExcel(file);
//        System.out.println(list.size());
        List<DbBlock> blocks = EasyExcelFactory.read(file)
                .head(DbBlock.class)
                .headRowNumber(3)
                .sheet("变量").doReadSync();
        System.out.println(blocks.size());

    }
}
